﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace sieuthi.Threelayer.DAL
{
    public class khachhangDAL:VO.ketnoi
    {
        public List<VO.khachhangVO> khachhang_xem()
        {
            List<VO.khachhangVO> list = new List<VO.khachhangVO>();
            using (SqlCommand dbCmd = new SqlCommand("khachhang_xem", GetConnection()))
            {
                VO.khachhangVO obj = new VO.khachhangVO();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.khachhangIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        public bool khachhang_them(VO.khachhangVO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("khachhang_them", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@diachi", data.DiaChi));
                    dbCmd.Parameters.Add(new SqlParameter("@hoten", data.Hoten));
                    dbCmd.Parameters.Add(new SqlParameter("@makh", data.MaKH));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }

            return true;
        }
        public bool khachhang_sua(VO.khachhangVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("khachhang_sua", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@diachi", data.DiaChi));
                dbCmd.Parameters.Add(new SqlParameter("@hoten", data.Hoten));
                dbCmd.Parameters.Add(new SqlParameter("@makh", data.MaKH));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool khachhang_xoa(string makh)
        {
            using (SqlCommand dbCmd = new SqlCommand("khachhang_xoa", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@makh", makh));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
    }
}
